/*****************************************************************************
 * 
 * Øving 2 UCSysDes
 *
 * Headerfil
 *
 *****************************************************************************/

#ifndef OEVING_2_H /* vanlig måte å unngå headerrekursjon på */
#define OEVING_2_H

#include <avr32/ap7000.h> /* inkludere Atmel-headerfil */
#include <sys/interrupts.h> /* included for interrupts */
#include <math.h>

#define PI 3.14159265
#define ushort unsigned short int

/* legg andre "includes" her, sammen med "defines" og prototyper */

/* prototyper */
int main (int argc, char *argv[]);
void createSineArray(float amplitude);
void initHardware (void);
__int_handler *button_int(void);
__int_handler *dac_int(void);

/*Array of sines between  16383 and -16383 for one octave*/
const double sines[12][168] = {
/*0 c4[168]*/{612.5799358290427, 612.5799358290427, 1224.3031232263886, 1834.3140120004925, 2441.759446764266, 3045.7898601500297, 3645.5604610062987, 4240.232415914598, 4828.974022373844, 5410.961872011502, 5985.382002194649, 6551.431034430317, 7108.317297962954, 7655.261936997575, 8191.500000000001, 8716.28150955076, 9228.87251125632, 9728.556100250678, 10214.633423851632, 10686.42465896946, 11143.269962900973, 11584.530396179207, 12009.588816188045, 12417.850740291957, 12808.745177273733, 13181.725425917328, 13536.269839618944, 13871.88255595698, 14188.09419020046, 14484.462491786022, 14760.572962845334, 15016.03943791782, 15250.504624037998, 15463.640600441986, 15655.149277194345, 15824.762812093806, 15972.243985274816, 16097.386530980963, 16200.01542604628, 16279.987134680994, 16337.189809219273, 16371.543446548334, 16383.0, 16371.543446548332, 16337.189809219273, 16279.987134680994, 16200.01542604628, 16097.386530980963, 15972.243985274816, 15824.762812093806, 15655.149277194345, 15463.640600441984, 15250.504624037998, 15016.03943791782, 14760.572962845334, 14484.462491786022, 14188.094190200458, 13871.882555956981, 13536.269839618943, 13181.725425917324, 12808.745177273735, 12417.850740291955, 12009.588816188043, 11584.530396179209, 11143.269962900971, 10686.424658969456, 10214.633423851632, 9728.556100250677, 9228.872511256317, 8716.281509550761, 8191.499999999999, 7655.261936997572, 7108.317297962956, 6551.431034430316, 5985.382002194647, 5410.961872011504, 4828.974022373843, 4240.232415914595, 3645.5604610063006, 3045.789860150029, 2441.759446764263, 1834.3140120004946, 1224.3031232263882, 612.5799358290398, 2.006338851043109E-12, -612.579935829043, -1224.3031232263913, -1834.3140120004905, -2441.759446764266, -3045.7898601500324, -3645.560461006297, -4240.232415914598, -4828.974022373846, -5410.9618720114995, -5985.38200219465, -6551.431034430319, -7108.317297962953, -7655.261936997575, -8191.500000000002, -8716.281509550763, -9228.87251125632, -9728.556100250678, -10214.633423851636, -10686.42465896946, -11143.269962900973, -11584.53039617921, -12009.588816188045, -12417.850740291957, -12808.745177273731, -13181.725425917331, -13536.269839618944, -13871.88255595698, -14188.094190200462, -14484.462491786024, -14760.572962845332, -15016.039437917821, -15250.504624037998, -15463.640600441984, -15655.149277194347, -15824.762812093806, -15972.243985274816, -16097.386530980963, -16200.01542604628, -16279.987134680994, -16337.189809219273, -16371.543446548334, -16383.0, -16371.543446548332, -16337.189809219273, -16279.987134680994, -16200.01542604628, -16097.38653098096, -15972.243985274816, -15824.762812093804, -15655.149277194343, -15463.640600441986, -15250.504624037996, -15016.03943791782, -14760.572962845335, -14484.462491786018, -14188.094190200458, -13871.882555956981, -13536.26983961894, -13181.725425917326, -12808.745177273735, -12417.850740291951, -12009.588816188043, -11584.53039617921, -11143.269962900968, -10686.424658969458, -10214.633423851634, -9728.556100250673, -9228.872511256319, -8716.281509550763, -8191.4999999999945, -7655.261936997574, -7108.317297962958, -6551.431034430311, -5985.3820021946485, -5410.961872011506, -4828.974022373838, -4240.2324159145965, -3645.560461006303, -3045.789860150024, -2441.759446764265, -1834.3140120004964, -1224.303123226383, -612.5799358290418},

/*1 cs4[159]*/{647.2367048102219, 647.2367048102219, 1293.4628263375032, 1937.6693592047359, 2578.8504513827656, 3216.004974708932, 3848.1380880298557, 4474.262790527801, 5093.401462805294, 5704.587393321755, 6306.86628779882, 6899.29775923757, 7480.956796221201, 8050.935207210546, 8608.343038577355, 9152.309964161237, 9681.986644180659, 10196.54605137617, 10695.184762315315, 11177.12421184294, 11641.611908718261, 12087.922610540618, 12515.359456129381, 12923.255053589972, 13310.972522367078, 13677.906487658032, 14023.484025633721, 14347.165557991118, 14648.445694440754, 14926.85402181367, 15181.955838555727, 15413.352833462493, 15620.683707594899, 15803.624738404642, 15961.890285188516, 16095.233235082473, 16203.445388899012, 16286.357786205506, 16343.840969135856, 16375.805184523579, 16382.200524040725, 16363.017002123815, 16318.284571565098, 16248.073076744837, 16152.49214457758, 16031.691013342774, 15885.858299666883, 15715.221704020923, 15520.047655193217, 15300.640894292455, 15057.34399893063, 14790.536848328775, 14500.636030180638, 14188.094190200458, 13853.399325370416, 13497.074021991273, 13119.674639725894, 12721.790442909689, 12304.042680484283, 11867.083615991067, 11411.595509139082, 10938.28955053748, 10447.904751255826, 9941.206788946012, 9418.986812327528, 8882.060205902617, 8331.265316830179, 7767.462145946225, 7191.531004974615, 6604.371142024849, 6006.899337522845, 5400.0484727671555, 4784.766073345577, 4162.012829686375, 3532.761097054281, 2897.993377333116, 2258.7007849657543, 1615.8814994465945, 970.5392067827188, 323.68153235739624, -323.6815323573922, -970.539206782722, -1615.8814994465904, -2258.7007849657575, -2897.9933773331118, -3532.761097054284, -4162.012829686379, -4784.766073345572, -5400.048472767158, -6006.899337522841, -6604.371142024852, -7191.531004974618, -7767.462145946221, -8331.265316830182, -8882.060205902613, -9418.98681232753, -9941.206788946016, -10447.904751255825, -10938.289550537482, -11411.595509139079, -11867.083615991069, -12304.042680484285, -12721.790442909693, -13119.674639725896, -13497.074021991271, -13853.399325370414, -14188.094190200462, -14500.63603018064, -14790.536848328777, -15057.34399893063, -15300.640894292454, -15520.047655193219, -15715.221704020925, -15885.858299666883, -16031.691013342772, -16152.49214457758, -16248.073076744837, -16318.284571565098, -16363.017002123815, -16382.200524040725, -16375.805184523579, -16343.840969135856, -16286.357786205506, -16203.445388899012, -16095.233235082473, -15961.890285188518, -15803.624738404638, -15620.683707594899, -15413.352833462493, -15181.955838555728, -14926.854021813671, -14648.44569444075, -14347.165557991117, -14023.484025633721, -13677.906487658034, -13310.972522367081, -12923.255053589968, -12515.35945612938, -12087.922610540618, -11641.611908718265, -11177.124211842945, -10695.184762315312, -10196.546051376168, -9681.986644180659, -9152.30996416124, -8608.34303857736, -8050.935207210541, -7480.956796221199, -6899.297759237571, -6306.866287798824, -5704.587393321761, -5093.401462805288, -4474.2627905278, -3848.1380880298566, -3216.004974708936, -2578.8504513827725, -1937.669359204731, -1293.4628263375014, -647.2367048102229},

/*2 d4[150]*/{686.0488350454774, 686.0488350454774, 1370.8941073133246, 2053.334365483996, 2732.1723774499033, 3406.217230667351, 4074.2864214218152, 4735.207929341277, 5387.822273518209, 6030.984546633078, 6663.566423510834, 7284.458140586667, 7892.5704428084, 8486.836494559991, 9066.213751253705, 9629.685788307586, 10176.264084299557, 10704.989755169896, 11214.935236429706, 11705.205910424216, 12174.94167579615, 12623.318456395753, 13049.549646990406, 13452.887493237471, 13832.62440349951, 14188.094190200458, 14518.67323854499, 14823.781600550798, 15102.884012474404, 15355.490833845657, 15581.1589064635, 15779.492331846033, 15950.143165770984, 16092.812028688106, 16207.248630932638, 16293.25221181842, 16350.671891840373, 16379.406937368394, 16379.406937368394, 16350.671891840373, 16293.252211818422, 16207.248630932638, 16092.812028688108, 15950.143165770985, 15779.492331846035, 15581.158906463503, 15355.490833845659, 15102.884012474406, 14823.781600550801, 14518.673238544992, 14188.09419020046, 13832.624403499514, 13452.887493237473, 13049.549646990408, 12623.318456395758, 12174.941675796154, 11705.205910424222, 11214.935236429708, 10704.9897551699, 10176.26408429956, 9629.68578830759, 9066.213751253712, 8486.836494559999, 7892.570442808406, 7284.458140586672, 6663.566423510839, 6030.984546633082, 5387.822273518212, 4735.207929341287, 4074.2864214218234, 3406.217230667358, 2732.172377449909, 2053.3343654840014, 1370.8941073133287, 686.0488350454805, 9.281852376016686E-12, -686.0488350454692, -1370.8941073133174, -2053.33436548399, -2732.1723774498982, -3406.217230667347, -4074.2864214218125, -4735.207929341269, -5387.822273518201, -6030.984546633071, -6663.566423510829, -7284.458140586661, -7892.570442808396, -8486.836494559988, -9066.213751253697, -9629.68578830758, -10176.264084299552, -10704.98975516989, -11214.935236429701, -11705.205910424214, -12174.941675796146, -12623.318456395747, -13049.549646990401, -13452.887493237467, -13832.624403499509, -14188.094190200456, -14518.673238544987, -14823.781600550796, -15102.884012474402, -15355.490833845657, -15581.1589064635, -15779.492331846033, -15950.143165770982, -16092.812028688104, -16207.248630932636, -16293.25221181842, -16350.671891840373, -16379.406937368394, -16379.406937368394, -16350.671891840373, -16293.252211818422, -16207.248630932638, -16092.812028688108, -15950.143165770985, -15779.492331846035, -15581.158906463503, -15355.490833845664, -15102.884012474411, -14823.781600550805, -14518.673238544996, -14188.094190200465, -13832.62440349952, -13452.887493237478, -13049.549646990414, -12623.31845639576, -12174.941675796155, -11705.205910424223, -11214.93523642971, -10704.989755169901, -10176.264084299562, -9629.685788307592, -9066.213751253721, -8486.836494560006, -7892.570442808415, -7284.45814058668, -6663.566423510847, -6030.984546633091, -5387.82227351822, -4735.207929341289, -4074.2864214218253, -3406.21723066736, -2732.172377449911, -2053.3343654840032, -1370.8941073133306, -686.0488350454824},

/*3 ds4[141]*/{729.8110674559459, 729.8110674559459, 1458.1731625919826, 2183.640189888619, 2904.771801715578, 3620.1362580086934, 4328.313268857279, 5027.896814358274, 5717.4979361386195, 6395.747495003536, 7061.29888923566, 7712.830728148111, 8349.049455583383, 8968.691918149358, 9570.527873093448, 10153.362430835692, 10716.038427311427, 11257.438721413417, 11776.488412972116, 12272.15697687046, 12743.460309056089, 13189.462680388862, 13609.278594444442, 14002.074545585478, 14367.0706738099, 14703.54231309077, 15010.821430133587, 15288.297950694574, 15535.420970826606, 15751.699850648003, 15936.705188462603, 16090.069673297088, 16211.488814162907, 16300.721544594962, 16357.590701266756, 16381.983375731774, 16373.851138592761, 16333.2101356538, 16260.141055864317, 16154.788971118638, 16017.363048229172, 15848.13613364507, 15647.444211740847, 15415.685737750518, 15153.32084667161, 14860.870439709706, 14538.915150077331, 14188.09419020046, 13809.104082621387, 13402.69727711772, 12969.680656782992, 12510.913936034942, 12027.307953732156, 11519.822864787791, 10989.466233870899, 10437.291034980022, 9864.393560860783, 9271.91124641814, 8661.020410444653, 8032.933920148391, 7388.8987831173945, 6730.193671501517, 6058.126383327214, 5374.031245985665, 4679.266467049189, 3975.211437675885, 3263.26399395615, 2544.8376416384863, 1821.358749744729, 1094.263718646329, 364.99612822442236, -364.9961282244183, -1094.2637186463248, -1821.358749744725, -2544.837641638482, -3263.2639939561464, -3975.211437675888, -4679.266467049185, -5374.0312459856605, -6058.1263833272105, -6730.193671501514, -7388.898783117397, -8032.933920148388, -8661.02041044465, -9271.911246418136, -9864.393560860779, -10437.291034980019, -10989.466233870895, -11519.822864787788, -12027.307953732152, -12510.913936034938, -12969.680656782984, -13402.697277117722, -13809.104082621385, -14188.094190200456, -14538.915150077333, -14860.870439709704, -15153.320846671606, -15415.68573775052, -15647.444211740847, -15848.136133645066, -16017.363048229172, -16154.788971118638, -16260.141055864317, -16333.210135653799, -16373.851138592761, -16381.983375731774, -16357.590701266756, -16300.721544594962, -16211.488814162907, -16090.069673297088, -15936.705188462603, -15751.699850648003, -15535.420970826608, -15288.297950694574, -15010.821430133588, -14703.542313090773, -14367.070673809898, -14002.074545585478, -13609.278594444446, -13189.46268038886, -12743.460309056089, -12272.156976870463, -11776.488412972123, -11257.438721413415, -10716.03842731143, -10153.3624308357, -9570.527873093446, -8968.691918149361, -8349.04945558339, -7712.830728148109, -7061.298889235662, -6395.747495003542, -5717.497936138616, -5027.896814358275, -4328.313268857284, -3620.136258008704, -2904.771801715578, -2183.6401898886234, -1458.173162591992, -729.8110674559454},

/*4 e4[133]*/{773.6777425942944, 773.6777425942944, 1545.6291076191985, 2314.1315697287328, 3077.4702994279214, 3833.941989527933, 4581.858655890451, 5319.551403980329, 6045.37415282187, 6757.707308049141, 7454.961375854302, 8135.5805097698185, 8798.045982370304, 9440.879574147264, 10062.646871994828, 10661.96046994629, 11237.48306501932, 11787.930441261835, 12312.074335339947, 12808.745177273733, 13276.834700205203, 13715.298413375005, 14123.157932789734, 14499.503164379195, 14843.494334772127, 15154.363865158986, 15431.418084060393, 15674.038775179453, 15881.684556884049, 16053.89209024096, 16190.277112906188, 16290.535296564505, 16354.442926004936, 16381.857398316854, 16372.717541092845, 16327.043748928272, 16244.937937912948, 16126.583318216497, 15972.243985274816, 15782.264330489905, 15557.068272757971, 15297.158312540614, 15003.114410589806, 14675.592693828683, 14315.323991275804, 13923.112203279852, 13499.832507703615, 13046.429407059948, 12563.914620957354, 12053.364828557917, 11515.919266085113, 10952.777184742305, 10365.195174714378, 9754.484361223687, 9122.007478897001, 8469.175830971704, 7797.446140126378, 7108.317297962956, 6403.327020393414, 5684.048416394307, 4952.086477785514, 4209.074497865906, 3456.67042689732, 2696.553172569266, 1930.4188536993497, 1159.9770155289825, 386.94681505947227, -386.9468150594755, -1159.9770155289784, -1930.4188536993456, -2696.5531725692617, -3456.6704268973162, -4209.074497865901, -4952.086477785517, -5684.048416394304, -6403.327020393411, -7108.317297962953, -7797.446140126375, -8469.1758309717, -9122.007478897005, -9754.48436122369, -10365.195174714374, -10952.777184742303, -11515.91926608511, -12053.364828557915, -12563.914620957352, -13046.429407059946, -13499.832507703617, -13923.11220327985, -14315.323991275805, -14675.592693828681, -15003.114410589804, -15297.158312540612, -15557.06827275797, -15782.264330489905, -15972.243985274816, -16126.583318216495, -16244.937937912948, -16327.043748928272, -16372.717541092845, -16381.857398316854, -16354.442926004935, -16290.535296564505, -16190.277112906188, -16053.89209024096, -15881.68455688405, -15674.038775179451, -15431.418084060395, -15154.363865158984, -14843.49433477213, -14499.503164379197, -14123.157932789736, -13715.298413375009, -13276.834700205201, -12808.745177273735, -12312.074335339943, -11787.930441261837, -11237.483065019325, -10661.96046994629, -10062.646871994832, -9440.879574147262, -8798.045982370308, -8135.580509769827, -7454.961375854302, -6757.707308049147, -6045.374152821869, -5319.551403980334, -4581.858655890448, -3833.941989527935, -3077.4702994279296, -2314.131569728733, -1545.6291076192047, -773.6777425942923},

/*5 f4[126]*/{816.6251447792016, 816.6251447792016, 1631.2200307792643, 2441.759446764266, 3246.2282640357307, 4042.626446360081, 4828.974022373844, 5603.316008104432, 6363.727267368324, 7108.317297962954, 7835.234931753056, 8542.672936966317, 9228.87251125632, 9892.127654362295, 10530.789409494575, 11143.269962900973, 11728.046591421968, 12283.66544822039, 12808.745177273733, 13301.980347642877, 13762.14469897909, 14188.09419020046, 14578.769843758291, 14933.200378422142, 15250.504624037998, 15529.89371225612, 15770.673037782048, 15972.243985274816, 16134.105417599007, 16255.854921730619, 16337.189809219273, 16377.907868719372, 16377.907868719372, 16337.189809219273, 16255.854921730619, 16134.105417599005, 15972.243985274816, 15770.673037782048, 15529.893712256118, 15250.504624037998, 14933.200378422142, 14578.76984375829, 14188.094190200458, 13762.14469897909, 13301.980347642875, 12808.745177273735, 12283.665448220388, 11728.04659142197, 11143.269962900971, 10530.789409494571, 9892.127654362295, 9228.872511256317, 8542.672936966317, 7835.234931753054, 7108.317297962956, 6363.727267368322, 5603.316008104426, 4828.974022373843, 4042.6264463600774, 3246.228264035731, 2441.759446764263, 1631.2200307792655, 816.6251447791996, 2.006338851043109E-12, -816.6251447792027, -1631.2200307792687, -2441.759446764266, -3246.2282640357344, -4042.6264463600805, -4828.974022373846, -5603.31600810443, -6363.727267368325, -7108.317297962953, -7835.234931753057, -8542.67293696632, -9228.87251125632, -9892.127654362297, -10530.789409494573, -11143.269962900973, -11728.046591421968, -12283.66544822039, -12808.745177273731, -13301.980347642877, -13762.14469897909, -14188.094190200462, -14578.769843758288, -14933.200378422142, -15250.504624037998, -15529.89371225612, -15770.673037782051, -15972.243985274816, -16134.105417599005, -16255.854921730619, -16337.189809219273, -16377.907868719372, -16377.907868719372, -16337.189809219273, -16255.854921730619, -16134.105417599005, -15972.243985274816, -15770.673037782048, -15529.893712256118, -15250.504624037996, -14933.200378422143, -14578.769843758291, -14188.094190200458, -13762.144698979086, -13301.980347642871, -12808.745177273735, -12283.66544822039, -11728.046591421966, -11143.269962900968, -10530.789409494568, -9892.127654362297, -9228.872511256319, -8542.672936966314, -7835.23493175305, -7108.317297962958, -6363.727267368324, -5603.316008104429, -4828.974022373838, -4042.626446360072, -3246.228264035733, -2441.759446764265, -1631.2200307792602, -816.6251447791943},

/*6 fs4[119]*/{864.618512038365, 864.618512038365, 1726.8271772083547, 2584.222865317039, 3434.415860801798, 4275.0365232962085, 5103.741892242753, 5918.222217144126, 6716.207395252135, 7495.473298751218, 8253.847973801581, 8989.217694164105, 9699.532852534478, 10382.813673166376, 11037.155729861546, 11660.735253947196, 12251.814217446385, 12808.745177273733, 13329.975866954772, 13814.053523071021, 14259.628934372207, 14665.460202269986, 15030.416202232082, 15353.479736429208, 15633.750368847874, 15870.446934967047, 16062.909719003785, 16210.602292659441, 16313.11301024155, 16370.156155994204, 16381.572740439104, 16347.33094350776, 16267.526203229725, 16142.380949729686, 15972.243985274816, 15757.589512100294, 15499.015810722627, 15197.24357242454, 14853.113890559114, 14467.58591627175, 14041.7341851739, 13576.745622419601, 13073.916234532166, 12534.647497201571, 11960.442449120352, 11352.901502745164, 10713.71798366023, 10044.67341097524, 9347.632531912048, 8624.53812441972, 7877.4055823039325, 7108.317297962956, 6319.41685838657, 5512.903070594635, 4691.0238331675755, 3856.0698709498247, 3010.3683503888724, 2156.2763933049523, 1296.1745071697785, 432.45995020523156, -432.4599502052276, -1296.1745071697746, -2156.276393304948, -3010.3683503888683, -3856.0698709498206, -4691.023833167572, -5512.903070594639, -6319.416858386566, -7108.317297962953, -7877.405582303929, -8624.538124419721, -9347.632531912044, -10044.673410975236, -10713.717983660226, -11352.90150274516, -11960.442449120348, -12534.64749720157, -13073.916234532164, -13576.7456224196, -14041.734185173902, -14467.585916271752, -14853.113890559116, -15197.243572424537, -15499.015810722625, -15757.589512100294, -15972.243985274816, -16142.380949729686, -16267.526203229725, -16347.33094350776, -16381.572740439104, -16370.156155994204, -16313.113010241552, -16210.602292659441, -16062.909719003785, -15870.446934967049, -15633.750368847874, -15353.479736429208, -15030.41620223208, -14665.460202269984, -14259.628934372211, -13814.053523071025, -13329.975866954774, -12808.745177273735, -12251.814217446385, -11660.735253947196, -11037.155729861544, -10382.813673166374, -9699.532852534485, -8989.21769416411, -8253.847973801587, -7495.4732987512225, -6716.207395252139, -5918.222217144128, -5103.741892242753, -4275.036523296206, -3434.415860801794, -2584.222865317048, -1726.827177208362, -864.6185120383707},


/*7 g4[112]*/{918.602137086913, 918.602137086913, 1834.3140120004925, 2744.2544564014966, 3645.5604610062987, 4535.396183673307, 5410.961872011502, 6269.502672437266, 7108.317297962954, 7924.766527445143, 8716.28150955076, 9480.371845313757, 10214.633423851632, 10916.755986587681, 11584.530396179207, 12215.855587280901, 12808.745177273733, 13361.33371615956, 13871.88255595698, 14338.785321131112, 14760.572962845334, 15135.918381132411, 15463.640600441986, 15742.708485426565, 15972.243985274816, 16151.524896384259, 16279.987134680994, 16357.226510436889, 16383.0, 16357.226510436889, 16279.987134680994, 16151.524896384259, 15972.243985274816, 15742.708485426567, 15463.640600441986, 15135.918381132411, 14760.572962845334, 14338.785321131112, 13871.882555956981, 13361.333716159561, 12808.745177273735, 12215.855587280903, 11584.530396179209, 10916.755986587683, 10214.633423851632, 9480.371845313759, 8716.281509550761, 7924.766527445145, 7108.317297962956, 6269.502672437267, 5410.961872011504, 4535.396183673309, 3645.5604610063006, 2744.2544564014984, 1834.3140120004946, 918.602137086915, 2.006338851043109E-12, -918.6021370869111, -1834.3140120004905, -2744.2544564014943, -3645.560461006297, -4535.396183673305, -5410.9618720114995, -6269.502672437264, -7108.317297962953, -7924.766527445142, -8716.281509550758, -9480.371845313755, -10214.633423851628, -10916.75598658768, -11584.530396179207, -12215.8555872809, -12808.745177273731, -13361.333716159554, -13871.88255595698, -14338.785321131114, -14760.572962845332, -15135.918381132407, -15463.640600441984, -15742.708485426567, -15972.243985274816, -16151.524896384257, -16279.987134680994, -16357.226510436889, -16383.0, -16357.226510436889, -16279.987134680994, -16151.524896384257, -15972.243985274816, -15742.708485426569, -15463.640600441986, -15135.91838113241, -14760.572962845335, -14338.785321131118, -13871.882555956981, -13361.333716159557, -12808.745177273735, -12215.855587280908, -11584.53039617921, -10916.75598658768, -10214.633423851634, -9480.371845313766, -8716.281509550763, -7924.76652744514, -7108.317297962958, -6269.502672437276, -5410.961872011506, -4535.396183673304, -3645.560461006303, -2744.2544564015075, -1834.3140120004964, -918.6021370869098},


/*8 gs4[106]*/{970.5392067827212, 970.5392067827212, 1937.6693592047359, 2897.9933773331127, 3848.1380880298557, 4784.766073345574, 5704.587393321755, 6604.371142024848, 7480.956796221201, 8331.265316830179, 9152.309964161237, 9941.206788946016, 10695.184762315315, 11411.59550913908, 12087.922610540618, 12721.790442909689, 13310.972522367078, 13853.399325370416, 14347.165557991118, 14790.536848328777, 15181.955838555727, 15520.047655193217, 15803.624738404642, 16031.691013342774, 16203.445388899012, 16318.284571565098, 16375.805184523579, 16375.805184523579, 16318.284571565098, 16203.445388899014, 16031.691013342774, 15803.62473840464, 15520.047655193217, 15181.955838555728, 14790.536848328775, 14347.165557991118, 13853.399325370416, 13310.972522367076, 12721.790442909689, 12087.922610540618, 11411.595509139082, 10695.184762315315, 9941.206788946012, 9152.309964161239, 8331.265316830179, 7480.956796221204, 6604.371142024849, 5704.587393321753, 4784.766073345577, 3848.1380880298543, 2897.993377333116, 1937.6693592047363, 970.5392067827188, 2.006338851043109E-12, -970.539206782722, -1937.6693592047395, -2897.9933773331118, -3848.1380880298575, -4784.766073345572, -5704.587393321755, -6604.371142024852, -7480.9567962212, -8331.265316830182, -9152.309964161237, -9941.206788946016, -10695.184762315319, -11411.595509139079, -12087.92261054062, -12721.790442909693, -13310.972522367078, -13853.399325370414, -14347.16555799112, -14790.536848328777, -15181.955838555727, -15520.047655193219, -15803.624738404642, -16031.691013342772, -16203.445388899012, -16318.284571565098, -16375.805184523579, -16375.805184523579, -16318.284571565098, -16203.445388899012, -16031.691013342774, -15803.624738404638, -15520.047655193217, -15181.955838555728, -14790.536848328773, -14347.165557991117, -13853.399325370416, -13310.972522367081, -12721.790442909687, -12087.922610540618, -11411.595509139084, -10695.184762315312, -9941.206788946014, -9152.30996416124, -8331.265316830173, -7480.956796221199, -6604.371142024851, -5704.587393321761, -4784.766073345571, -3848.1380880298566, -2897.9933773331177, -1937.669359204731, -970.5392067827207},

/*9 a4[100]*/{1028.697081448741, 1028.697081448741, 2053.3343654839964, 3069.8680768579266, 4074.286421421816, 5062.625418844764, 6030.984546633079, 6975.542133710586, 7892.570442808402, 8778.450382140902, 9629.685788307586, 10442.917224052784, 11214.935236429706, 11942.693023044985, 12623.318456395755, 13254.125418844764, 13832.624403499512, 14356.532339158619, 14823.7816005508, 15232.528168307224, 15581.1589064635, 15868.297928770364, 16092.812028688108, 16253.815151635092, 16350.671891840373, 16383.0, 16350.671891840373, 16253.81515163509, 16092.812028688106, 15868.297928770364, 15581.1589064635, 15232.528168307224, 14823.781600550798, 14356.532339158615, 13832.62440349951, 13254.125418844764, 12623.318456395755, 11942.693023044983, 11214.935236429703, 10442.91722405278, 9629.68578830759, 8778.450382140902, 7892.5704428084, 6975.542133710583, 6030.984546633075, 5062.625418844758, 4074.2864214218166, 3069.8680768579256, 2053.334365483994, 1028.6970814487372, -5.269174673930468E-12, -1028.6970814487406, -2053.3343654839973, -3069.868076857929, -4074.28642142182, -5062.625418844768, -6030.984546633084, -6975.542133710585, -7892.570442808403, -8778.450382140903, -9629.685788307592, -10442.917224052788, -11214.935236429706, -11942.693023044985, -12623.318456395757, -13254.125418844762, -13832.624403499516, -14356.532339158617, -14823.781600550803, -15232.528168307224, -15581.1589064635, -15868.297928770366, -16092.812028688108, -16253.815151635092, -16350.671891840373, -16383.0, -16350.671891840373, -16253.815151635092, -16092.812028688106, -15868.297928770364, -15581.158906463503, -15232.52816830722, -14823.7816005508, -14356.532339158613, -13832.62440349951, -13254.125418844756, -12623.318456395751, -11942.693023044985, -11214.9352364297, -10442.917224052782, -9629.685788307579, -8778.450382140896, -7892.570442808402, -6975.542133710578, -6030.984546633077, -5062.625418844753, -4074.286421421811, -3069.8680768579275, -2053.334365483989, -1028.6970814487393},

/*10 as4[94]*/{1094.2637186463264, 1094.2637186463264, 2183.640189888619, 3263.263993956147, 4328.313268857279, 5374.0312459856605, 6395.747495003536, 7388.898783117395, 8349.049455583383, 9271.91124641814, 10153.362430835692, 10989.466233870897, 11776.488412972116, 12510.91393603494, 13189.462680388862, 13809.104082621385, 14367.0706738099, 14860.870439709704, 15288.297950694574, 15647.444211740847, 15936.705188462603, 16154.788971118638, 16300.721544594962, 16373.851138592761, 16373.851138592761, 16300.721544594962, 16154.788971118638, 15936.705188462603, 15647.444211740847, 15288.297950694576, 14860.870439709706, 14367.070673809902, 13809.104082621387, 13189.462680388864, 12510.913936034942, 11776.488412972118, 10989.466233870899, 10153.362430835692, 9271.91124641814, 8349.049455583381, 7388.8987831173945, 6395.74749500354, 5374.031245985665, 4328.313268857282, 3263.26399395615, 2183.6401898886215, 1094.263718646329, 2.006338851043109E-12, -1094.2637186463248, -2183.6401898886174, -3263.2639939561464, -4328.313268857279, -5374.0312459856605, -6395.747495003537, -7388.898783117397, -8349.049455583385, -9271.911246418136, -10153.362430835688, -10989.466233870895, -11776.488412972114, -12510.913936034938, -13189.462680388866, -13809.104082621385, -14367.070673809902, -14860.870439709704, -15288.297950694572, -15647.444211740847, -15936.705188462602, -16154.788971118638, -16300.721544594962, -16373.851138592761, -16373.851138592761, -16300.721544594962, -16154.788971118638, -15936.705188462603, -15647.444211740849, -15288.297950694574, -14860.870439709706, -14367.070673809898, -13809.104082621387, -13189.46268038886, -12510.913936034942, -11776.488412972123, -10989.466233870899, -10153.3624308357, -9271.911246418142, -8349.04945558339, -7388.898783117396, -6395.747495003542, -5374.03124598566, -4328.313268857284, -3263.263993956145, -2183.6401898886234, -1094.2637186463237},

/*11 b4[89]*/{1155.6397659901804, 1155.6397659901804, 2305.5221927966436, 3443.9186240098816, 4565.157625872671, 5663.653242077765, 6733.932822721237, 7770.664288769021, 8768.682696206442, 9723.015967529498, 10628.909662384878, 11481.85066395265, 12277.589663067238, 13012.162328061942, 13681.909054869882, 14283.49319898739, 14813.917698469071, 15270.540005139666, 15651.08524963615, 15953.657574692443, 16176.749580204965, 16319.24983302412, 16380.448404058348, 16360.040405105136, 16258.127507788713, 16075.21743703714, 15812.22144162224, 15470.449754364074, 15051.60506461692, 14557.774035556573, 13991.416908529356, 13355.355246253495, 12652.757875935566, 11887.125102332773, 11062.271269410718, 10182.305757473596, 9251.61251043828, 8274.828195246198, 7256.819102221901, 6202.656901459425, 5117.59337601699, 4007.03425779801, 2876.5122964666175, 1731.6596955671912, 578.1800531695844, -578.1800531695804, -1731.659695567187, -2876.5122964666134, -4007.034257797999, -5117.593376016986, -6202.6569014594215, -7256.819102221897, -8274.828195246195, -9251.612510438272, -10182.305757473592, -11062.271269410714, -11887.12510233277, -12652.757875935557, -13355.355246253488, -13991.416908529354, -14557.774035556571, -15051.60506461692, -15470.44975436407, -15812.221441622238, -16075.217437037138, -16258.127507788713, -16360.040405105136, -16380.44840405835, -16319.249833024121, -16176.749580204965, -15953.657574692443, -15651.08524963615, -15270.54000513967, -14813.917698469073, -14283.493198987391, -13681.909054869884, -13012.16232806194, -12277.589663067245, -11481.850663952655, -10628.909662384882, -9723.015967529498, -8768.68269620644, -7770.6642887690305, -6733.932822721244, -5663.653242077769, -4565.157625872673, -3443.91862400988, -2305.5221927966536, -1155.6397659901875}
};
 
//length of the sine samples
const short toneSampleLength[12] = {168, 159, 150, 141, 133,126, 119, 112, 106, 100, 94, 89};

//a selection of power of two numbers used to shift between octaves
const short powerOfTwo[5] = {1, 2, 4, 8, 16};

typedef struct
{
  ushort length;
  short note;
  short octave;
  float volume;
}Note;

typedef struct
{
  int noteCountLeft;
  int noteCountRight;
  int currentNoteLeft;
  int currentNoteRight;
  int noteTimerLeft;
  int noteTimerRight;
  Note notesLeft[50];
  Note notesRight[50];
}Song;

typedef struct
{
  int left;
  int leftRest;
  int right;
  int rightRest;
  short isActiveRight;
  short isActiveLeft;
  Song *song_ptr;
}Channel;

short playSine(short note, short octave, float volume, Channel *channel, short isRight);
void loadSong(Channel * channel, Song *song);
short playSong(Channel *channel, short isRight);
short play(short isRight);
#endif
